//
//  CoordinateView.m
//  CoreAnimation
//
//  Created by LG on 2018/5/18.
//  Copyright © 2018年 iqiyi. All rights reserved.
//

#import "CoordinateView.h"

@interface CoordinateView ()

@property (nonatomic, strong) CAReplicatorLayer *xReplicatorLayer;
@property (nonatomic, strong) CAReplicatorLayer *yReplicatorLayer;
@property (nonatomic, strong) CALayer *xBackLine;
@property (nonatomic, strong) CALayer *yBackLine;


@end

@implementation CoordinateView

- (instancetype)init
{
    self = [super init];
    if (self) {
        //添加网格图层
        //网格列线
        CAReplicatorLayer *rowReplicatorLayer = [CAReplicatorLayer new];
        _xReplicatorLayer = rowReplicatorLayer;
        rowReplicatorLayer.position= CGPointMake(0,0);
        CALayer *rowBackLine = [CALayer new];
        _xBackLine = rowBackLine;
        [rowReplicatorLayer addSublayer:rowBackLine];
        [self.layer addSublayer:rowReplicatorLayer];
        //网格横线
        CAReplicatorLayer *columnReplicatorLayer = [CAReplicatorLayer new];
        _yReplicatorLayer = columnReplicatorLayer;
        columnReplicatorLayer.position= CGPointMake(0,0);
        CALayer *columnBackLine = [CALayer new];
        _yBackLine = columnBackLine;
        [columnReplicatorLayer addSublayer:columnBackLine];
        [self.layer addSublayer:columnReplicatorLayer];
        
        CGFloat _numberY = 10;
        CGFloat _valueData = 5;
        _xReplicatorLayer.instanceCount= _numberY+1;
        _yReplicatorLayer.instanceCount= _valueData;//.count;
        
        /*//图层绘制动画
        [CATransaction begin];
        [CATransaction setAnimationDuration:0];
        CGFloat heightGrid = 30;
        CGFloat widthGrid = 30;
        CGFloat rowSpacing = heightGrid;
        CGFloat columnSpacing = widthGrid;
//        //坐标轴这里我简单的使用label循环创建
//        _XLabelView.frame= CGRectMake(_YLabelWidth-widthGrid/2,_mainView.frame.size.height-_XLabelHeight,_mainView.frame.size.width-_YLabelWidth,_XLabelHeight);
//        _YLabelView.frame= CGRectMake(0,0-_heightGrid/2+_YunitLabelHeight,_YLabelWidth,_mainView.frame.size.height-_XLabelHeight);
        //图层复制（设置复制的数量）
        CGFloat _numberY = 10;
        CGFloat _valueData = 5;
        _xReplicatorLayer.instanceCount= _numberY+1;
        _yReplicatorLayer.instanceCount= _valueData;//.count;
        
//        _xReplicatorLayer.instanceTransform= CATransform3DMakeTranslation(0, rowSpacing + _widthLine,0);
//        _yReplicatorLayer.instanceTransform= CATransform3DMakeTranslation(columnSpacing +_widthLine,0,0);
//        //设置图层大小
//        _yReplicatorLayer.frame= _xReplicatorLayer.frame= CGRectMake(_YLabelWidth,_YunitLabelHeight,_mainView.frame.size.width-_YLabelWidth-_spaceWidth,_mainView.frame.size.height-_XLabelHeight-_YunitLabelHeight);
//
//        _yBackLine.frame= CGRectMake(0,0,_widthLine,_yReplicatorLayer.frame.size.height);
//        _xBackLine.frame= CGRectMake(0,0,_yReplicatorLayer.frame.size.width,_widthLine);
        [CATransaction commit];*/
        
//        2.绘制曲线和折点
        //曲线
//        _curveLineLayer.strokeColor= _curveLineColor.CGColor;
//        _curveLineLayer.lineWidth= _curveLineWidth;
//
//        CAShapeLayer *curveLineLayer = [CAShapeLayernew];
//        _curveLineLayer = curveLineLayer;
//        curveLineLayer.fillColor= nil;
//        curveLineLayer.lineJoin= kCALineJoinRound;
//        [mainView.layeraddSublayer:curveLineLayer];
    }
    return self;
}

@end
